//
// Deterministic epidemic model implementation of the epidemic state 
// of one AS.
//
// @author Michael Liljenstam, ISTS, Dartmouth College
//
// $Id: DeterministicWormEpidemicState.java,v 1.3 2003/03/03 19:09:43 mili Exp mili $

package SSF.App.Worm;

//.............................................................
/**
 *  Deterministic epidemic model implementation epidemic model.
 *  Contains epidemic state of one AS.
 */
public class DeterministicWormEpidemicState extends WormEpidemicState {

    boolean DEBUG = false;
    //    boolean DEBUG = true;

    public DeterministicWormEpidemicState(AS myAS) {
	super(myAS);
    }

    /**
     *  One timestep.
     */
    public void update(float iTot) {
	// refs to global data
	int numASs = MacroscopicModel.ref.net.numASs;
	float[] BetaJ = MacroscopicModel.ref.wormModel.BetaJ;
	float DeltaT = MacroscopicModel.ref.DeltaT;
	float t = MacroscopicModel.ref.t;
	float gamma = ((DeterministicWormEpidemic)MacroscopicModel.ref
		       .wormModel).gammaFctn.gamma(t, i, iTot);

	int j = myAS.index;
	float next_s = 
	    Math.max(0, -BetaJ[j] * s * iTot * DeltaT + s);
	float next_i = 
	    Math.min(N, (BetaJ[j] * s * iTot - gamma) 
		     * DeltaT + i); // Uniform recover distr
	float next_r = 
	    Math.min(N, gamma * DeltaT + r);

	if (DEBUG) {
		System.out.println("t: "+t+" AS "+myAS.asNumber+" before: s="+s+", i="+i+", r="+r
		+" - after: s="+next_s+", i="+next_i+", r="+next_r);
		System.out.println("N=" + N + " gamma=" + gamma);

	}

	// trigger infections in hosts
	myAS.triggerInfections((int) Math.floor(next_i 
						- myAS.triggeredInfections));

	// separate for clarity
	s = next_s; i = next_i; r = next_r;

    } // update

    public void output() {
	System.out.print("  " + s + "  " + i + "  " + r);
    }

} // class DeterministicWormEpidemic


